﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TalentPools.Model;

namespace TalentPools.DAL
{
   public class SkillService
    {
       public bool DeleteSkill(int resumeId)
       {
           string sql = "delete from skill where resumeId=@resumeId";
           SqlParameter para=new SqlParameter("@resumeId",resumeId);
           return DBHelper.ExecuteNonQuery(CommandType.Text, sql, para) > 0;
       }
       public bool UpdateSkill(Skill skill)
       {
           string sql = "update skill set name=@name where resumeId=@resumeId";
           SqlParameter[] paras = new SqlParameter[] { 
           new SqlParameter("@name",skill.Name),
           new SqlParameter("@resumeId",skill.resumeId)
           };
           return DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras) == 1;
       }
       public bool InsertSkill(Skill skill)
       {
           string sql = "insert into skill(Name,resumeId)values(@Name,@resumeId)";
           SqlParameter[] paras = new SqlParameter[] { 
           new SqlParameter("@Name",skill.Name),
           new SqlParameter("@resumeId",skill.resumeId)
           };
           return DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras) ==1;
       }
       public List<Skill> GetSkill(int resumeId)
       {
           string sql = "select * from skill where resumeId=@resumeId";
           SqlParameter para = new SqlParameter("@resumeId", resumeId);
           List<Skill> list = new List<Skill>();
           using (SqlDataReader dr=DBHelper.ExecuteGetReader(CommandType.Text,sql,para))
           {
               while (dr.Read())
               {
                   Skill skill = new Skill();
                   skill.Id = Convert.ToInt32(dr["Id"]);
                   skill.Name = dr["Name"].ToString();
                   skill.resumeId = Convert.ToInt32(dr["resumeId"]);
                   list.Add(skill);
               }
               return list;
           }
       }
    }
}
